package view.macro
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.utils.Dictionary;
	import model.macro.Territory;
	import model.macro.World;
	import util.Assets;
	
	/**
	 */
	public class MapSprite extends Sprite
	{
		private var sprite_map:Dictionary = new Dictionary();
		private var background:Bitmap;
		
		public function MapSprite(territories:Vector.<Territory>, world:World)
		{
			y = -20;
			background = new Assets.MapBackground();
			addChild(background);
			
			for (var i:int = 0; i < territories.length; i++)
			{
				var sprite:TerritorySprite = new TerritorySprite(territories[i], world);
				// Should be read from territory.location I think
				sprite.x = (i % 4) * 100 + 200;
				sprite.y = int(i / 4) * 100 + 180;
				sprite_map[territories[i]] = sprite;
				
				addChild(sprite);
				
				// Adjacency lines
				graphics.lineStyle(2, 0x00FF00);
				for (var j:int = i; j < territories.length; j++)
				{
					if (territories[j].adjacent_territories.indexOf(territories[i]) >= 0)
					{
						graphics.moveTo(sprite.x, sprite.y);
						graphics.lineTo((j % 4) * 100, int(j / 4) * 100);
					}
				}
			}
		}
		
		/**
		 *
		 * @param	territory
		 * @return
		 */
		public function getTerritorySprite(territory:Territory):TerritorySprite
		{
			return (sprite_map[territory] as TerritorySprite);
		}
	}
}